package com.chaidb;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;

import com.db.DbConnection;

public class ShowTypeMarkers {
	@SuppressWarnings({ "finally", "unchecked" })
	public ArrayList doShowTypeMarkers(String markertype)
	{
		System.out.println("I am here in ShowTypeMarkers");
		String querysql = "select * from marker where type='" + markertype +"';";
		System.out.println(querysql);
		
		ArrayList markers = new ArrayList();
		HashMap marker;
		Connection con = null;
		try {
			con = DbConnection.getInstance().getConnection();
			Statement st = con.createStatement();
			ResultSet query =st.executeQuery(querysql);
			while(query.next())
			{
				marker = new HashMap<String,Object>();
				marker.put("id",query.getString("id"));
				marker.put("state", query.getString("state"));
				marker.put("markername", query.getString("markername"));
				marker.put("userid", query.getString("userid"));
				marker.put("type", query.getString("type"));
				marker.put("description", query.getString("description"));
				marker.put("longitude", query.getString("longitude"));
				marker.put("latitude", query.getString("latitude"));
				marker.put("musicurl", query.getString("musicurl"));
				marker.put("createtime", query.getString("createtime"));
			
				String sql3 = "select * from user where id='" +query.getString("userid")+"';";
				Statement st3 = con.createStatement();
				ResultSet query3 = st3.executeQuery(sql3);
				if(query3.next())
					marker.put("creater",query3.getString("username"));
				markers.add(marker);
				
			}
		}catch(SQLException e)
		{
			e.printStackTrace();
		}finally
		{
			try {
				con.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
			return markers;
		}
	}

}
